﻿<!DOCTYPE html>
<!--[if IE]><![endif]-->
<html>

  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Getting started </title>
    <meta name="viewport" content="width=device-width">
    <meta name="title" content="Getting started ">
    <meta name="generator" content="docfx ">
  
    <link rel="shortcut icon" href="../../api/images/favicon.ico">
    <link rel="stylesheet" href="../../styles/docfx.vendor.css">
    <link rel="stylesheet" href="../../styles/docfx.css">
    <link rel="stylesheet" href="../../styles/main.css">
    <link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet"> 
    <meta property="docfx:navrel" content="../../toc.html">
    <meta property="docfx:tocrel" content="../toc.html">
    <script type="text/javascript" async="" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML"></script>
  
  
  
  </head>  <body data-spy="scroll" data-target="#affix" data-offset="120">
    <div id="wrapper">
      <header>

        <nav id="autocollapse" class="navbar navbar-inverse ng-scope" role="navigation">
          <div class="container">
            <div class="navbar-header">
              <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
              </button>

              <a class="navbar-brand" href="../../index.html">
                <img id="logo" class="svg" src="../../api/images/favicon.svg" alt="">
              </a>
            </div>
            <div class="collapse navbar-collapse" id="navbar">
              <form class="navbar-form navbar-right" role="search" id="search">
                <div class="form-group">
                  <input type="text" class="form-control" id="search-query" placeholder="Search" autocomplete="off">
                </div>
              </form>
            </div>
          </div>
        </nav>

        <div class="subnav navbar navbar-default">
          <div class="container hide-when-search" id="breadcrumb">
            <ul class="breadcrumb">
              <li></li>
            </ul>
          </div>
        </div>
      </header>
      <div role="main" class="container body-content hide-when-search">

        <div class="sidenav hide-when-search">
          <a class="btn toc-toggle collapse" data-toggle="collapse" href="#sidetoggle" aria-expanded="false" aria-controls="sidetoggle">Show / Hide Table of Contents</a>
          <div class="sidetoggle collapse" id="sidetoggle">
            <div id="sidetoc"></div>
          </div>
        </div>
        <div class="article row grid-right">
          <div class="col-md-10">
            <article class="content wrap" id="_content" data-uid="">
<h1 id="getting-started">Getting started</h1>

<p>In this section we will try to quickly go over everything you need to create a simple circuit and simulate it using Spice#.</p>
<h2 id="installation">Installation</h2>
<p>The easiest way to install Spice# is by installing the NuGet package Spice#.</p>
<p><a href="https://www.nuget.org/packages/SpiceSharp/"><img src="https://buildstats.info/nuget/spicesharp" alt="NuGet Badge"></a></p>
<p>You can also <strong>clone</strong> the repository directly. However, while you get the latest features and bug fixes, the documentation might not be up to date!</p>
<table>
<thead>
<tr>
<th style="text-align: left;"></th>
<th style="text-align: right;">Status</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;">Windows</td>
<td style="text-align: right;"><img src="https://github.com/SpiceSharp/SpiceSharp/workflows/Windows%20Tests/badge.svg" alt="Windows Tests"></td>
</tr>
<tr>
<td style="text-align: left;">MacOS</td>
<td style="text-align: right;"><img src="https://github.com/SpiceSharp/SpiceSharp/workflows/MacOS%20Tests/badge.svg" alt="MacOS Tests"></td>
</tr>
<tr>
<td style="text-align: left;">Linux/Ubuntu</td>
<td style="text-align: right;"><img src="https://github.com/SpiceSharp/SpiceSharp/workflows/Linux%20Tests/badge.svg" alt="Linux Tests"></td>
</tr>
</tbody>
</table>
<h2 id="building-a-circuit">Building a circuit</h2>
<p>Let's start with a very simple circuit known as a <em>resistive voltage divider</em>. The schematic looks as follows.</p>
<p align="center"><img src="images/example01.svg" width="256px"></p>
<p>The output voltage of this circuit is 2/3 times the input voltage for those wondering.</p>
<p>The components are stored in a <strong><a class="xref" href="../../api/SpiceSharp.Circuit.html">Circuit</a></strong>. This is a container for so-called entities (<strong><a class="xref" href="../../api/SpiceSharp.Entities.IEntity.html">IEntity</a></strong>), which is the term for anything that can affect simulations. The <strong><a class="xref" href="../../api/SpiceSharp.Circuit.html">Circuit</a></strong> is defined in the namespace <em><a class="xref" href="../../api/SpiceSharp.html">SpiceSharp</a></em>, while all default components are typically specified in the namespace <em><a class="xref" href="../../api/SpiceSharp.Components.html">SpiceSharp.Components</a></em>.</p>
<pre><code class="lang-csharp" name="Circuit">// Build the circuit
var ckt = new Circuit(
    new VoltageSource(&quot;V1&quot;, &quot;in&quot;, &quot;0&quot;, 1.0),
    new Resistor(&quot;R1&quot;, &quot;in&quot;, &quot;out&quot;, 1.0e4),
    new Resistor(&quot;R2&quot;, &quot;out&quot;, &quot;0&quot;, 2.0e4)
    );
</code></pre><h2 id="running-a-dc-analysis-on-the-circuit">Running a DC analysis on the circuit</h2>
<p>A <strong><a class="xref" href="../../api/SpiceSharp.Simulations.DC.html">DC</a></strong> simulation will sweep a voltage or current source value (or anything else in Spice#). The result is a transfer curve in function of the swept parameter.</p>
<p>We will sweep the input voltage source from -1V to 1V in steps of 200mV.</p>
<pre><code class="lang-csharp" name="Simulation">// Create a DC simulation that sweeps V1 from -1V to 1V in steps of 100mV
var dc = new DC(&quot;DC 1&quot;, &quot;V1&quot;, -1.0, 1.0, 0.2);

// Catch exported data
foreach (int _ in dc.Run(ckt))
{
    double input = dc.GetVoltage(&quot;in&quot;);
    double output = dc.GetVoltage(&quot;out&quot;);
}
</code></pre>
<p>Access to simulation output data is usually achieved by using extension methods. These extension methods contain some code to access the most common aspects of the simulation states (like voltages and currents).</p>
<p>The output will show:</p>
<pre><code>-1 V : -0.667 V
-0.8 V : -0.533 V
-0.6 V : -0.4 V
-0.4 V : -0.267 V
-0.2 V : -0.133 V
0 V : 0 V
0.2 V : 0.133 V
0.4 V : 0.267 V
0.6 V : 0.4 V
0.8 V : 0.533 V
1 V : 0.667 V
</code></pre>
<h2 id="using-exports">Using exports</h2>
<p>Using exports allows for faster access to voltages, currents, circuit properties, etc. compared to using the extension methods. For example, we could be interested in the current through voltage source V1. In which case we can define some exports like this:</p>
<pre><code class="lang-csharp" name="Simulation">// Create a DC simulation that sweeps V1 from -1V to 1V in steps of 100mV
var dc = new DC(&quot;DC 1&quot;, &quot;V1&quot;, -1.0, 1.0, 0.2);

// Create exports
var inputExport = new RealVoltageExport(dc, &quot;in&quot;);
var outputExport = new RealVoltageExport(dc, &quot;out&quot;);
var currentExport = new RealPropertyExport(dc, &quot;V1&quot;, &quot;i&quot;);

// Catch exported data
foreach (int _ in dc.Run(ckt))
{
    double input = inputExport.Value;
    double output = outputExport.Value;
    double current = currentExport.Value;
}
</code></pre>
<p>This will lead to the result:</p>
<ol>
<li><code>input = -1</code> (V), <code>output = -0.667</code> (V), <code>current = 3.33e-05</code> (A)</li>
<li><code>input = -0.8</code> (V), <code>output = -0.533</code> (V), <code>current = 2.67e-05</code> (A)</li>
<li><code>input = -0.6</code> (V), <code>output = -0.4</code> (V), <code>current = 2e-05</code> (A)</li>
<li><code>input = -0.4</code> (V), <code>output = -0.267</code> (V), <code>current = 1.33e-05</code> (A)</li>
<li><code>input = -0.2</code> (V), <code>output = -0.133</code> (V), <code>current = 6.67e-06</code> (A)</li>
<li><code>input = 0</code> (V), <code>output = 0</code> (V), <code>current = 0</code> (A)</li>
<li><code>input = 0.2</code> (V), <code>output = 0.133</code> (V), <code>current = -6.67e-06</code> (A)</li>
<li><code>input = 0.4</code> (V), <code>output = 0.267</code> (V), <code>current = -1.33e-05</code> (A)</li>
<li><code>input = 0.6</code> (V), <code>output = 0.4</code> (V), <code>current = -2e-05</code> (A)</li>
<li><code>input = 0.8</code> (V), <code>output = 0.533</code> (V), <code>current = -2.67e-05</code> (A)</li>
<li><code>input = 1</code> (V), <code>output = 0.667</code> (V), <code>current = -3.33e-05</code> (A)</li>
</ol>

</article>
          </div>

          <div class="hidden-sm col-md-2" role="complementary">
            <div class="sideaffix">
              <nav class="bs-docs-sidebar hidden-print hidden-xs hidden-sm affix" id="affix">
                <h5>In this article</h5>
                <div></div>
              </nav>
            </div>
          </div>
        </div>
      </div>

      <footer>
        <div class="grad-bottom"></div>
        <div class="footer">
          <div class="container">
            <span class="pull-right">
              <a href="#top">Back to top</a>
            </span>
      
      <span>Generated by <strong>DocFX</strong></span>
          </div>
        </div>
      </footer>
    </div>

    <script type="text/javascript" src="../../styles/docfx.vendor.min.js"></script>
    <script type="text/javascript" src="../../styles/docfx.js"></script>
    <script type="text/javascript" src="../../styles/main.js"></script>
  </body>
</html>
